package top.xierongsheng.user.validate.impl;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;
import top.xierongsheng.user.model.SysArea;
import top.xierongsheng.user.service.IAreaService;
import top.xierongsheng.user.validate.ValidArea;


public class AreaValidator implements ConstraintValidator<ValidArea, Integer> {

    @Autowired
    private IAreaService areaService;

    @Override
    public void initialize(ValidArea constraintAnnotation) {
    }

    @Override
    public boolean isValid(Integer param, ConstraintValidatorContext constraintValidatorContext) {
        SysArea sysArea = areaService.getByAreaId(param);
        if (sysArea == null) {
            return false;
        }
        return true;
    }
}
